﻿using System.Runtime.InteropServices;
using System.Text;

namespace GetContent
{
    class Configs
    {
        public static string Path = "";
        
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
        [DllImport("kernel32")]
        private static extern long GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filepath);

        public static string AutoRestart = "1";
        public static bool Optimize = true;
        public static bool DisableCSS = false;
        public static bool DisableImages = false;
        public static bool DisableJs = false;
        public static bool DisableFlash = false;

        public static void Setting()
        {
            var exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            Path = exePath.Remove(exePath.LastIndexOf('\\') + 1);
        }

        public static string ReadValue(string key, string section = "Configs")
        {
            var tmp = new StringBuilder(255);
            GetPrivateProfileString(section, key, "", tmp, 255, Path + "config.ini");
            return tmp.ToString();
        }

        public static void WriteValue(string key, string value, string section = "Configs")
        {
            WritePrivateProfileString(section, key, value, Path + "config.ini");
        }
    }
}
